using Blog2025.Application.Events;
using Blog2025.Domain.Events;
using MediatR;
using Microsoft.Extensions.Logging;

namespace Blog2025.Application.EventHandlers;

/// <summary>
/// 用户删除事件处理器 - 记录审计日志
/// </summary>
public class UserDeletedAuditHandler : INotificationHandler<DomainEventNotification>
{
    private readonly ILogger<UserDeletedAuditHandler> _logger;

    public UserDeletedAuditHandler(ILogger<UserDeletedAuditHandler> logger)
    {
        _logger = logger;
    }

    public async Task Handle(DomainEventNotification notification, CancellationToken cancellationToken)
    {
        // 只处理用户删除事件
        if (notification.DomainEvent is UserDeletedEvent userEvent)
        {
            _logger.LogInformation("用户删除审计: 事件ID={EventId}, 用户ID={UserId}, 用户名={Username}, 删除者={DeletedBy}, 删除时间={OccurredOn}",
                userEvent.EventId,
                userEvent.UserId,
                userEvent.Username,
                userEvent.DeletedBy,
                userEvent.OccurredOn);

            // 这里可以记录到审计日志表
            await Task.CompletedTask;
        }
    }
}
